package com.dcbeida.model;

import com.dcbeida.MyApplication;
import com.dcbeida.bean.CouponDrug;
import com.dcbeida.bean.DrugCodeInfo;
import com.dcbeida.utils.GenApiHashUrl;
import com.dcbeida.utils.JsonGet;

import java.util.List;

import dc.medicine.com.okhttplib.OkHttpUtils;
import dc.medicine.com.okhttplib.callback.AbsCallback;

/**
 * Created by hp on 2016/7/27.
 */
public class ZyFFModel {

    private static ZyFFModel mInventoryModel;

    private ZyFFModel() {

    }

    public static ZyFFModel newInstance() {
        if (mInventoryModel == null) {
            return new ZyFFModel();
        } else {
            return mInventoryModel;
        }
    }


    /**
     * 37.	赠药-根据监管码查询已购药品信息
     *
     * @param drugcode
     * @param mAbsCallback
     */
    public void querydrugcode(String drugcode, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "querydrugcode")
                .paramsApp("params", new JsonGet().putopt("drugcode", drugcode).putopt("uid", MyApplication.user.getUid()).tostring()).execute(mAbsCallback);
    }


    public void querycouponcode(String couponcode, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "querycouponcode")
                .paramsApp("params", new JsonGet().putopt("couponcode", couponcode).tostring()).execute(mAbsCallback);
    }


    public void querydruginfo(String drugcode, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "querydruginfo")
                .paramsApp("params", new JsonGet().putopt("drugcode", drugcode).putopt("uid", MyApplication.user.getUid()).tostring()).execute(mAbsCallback);
    }


    public void calcpresenddruglist(DrugCodeInfo drugCodeInfo, String codes, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "calcpresenddruglist")
                .paramsApp("params", new JsonGet().putopt("truename", drugCodeInfo.getTruename()).
                        putopt("idcardnum", drugCodeInfo.getIdcardnum())
                        .putopt("phonenum", drugCodeInfo.getPhonenum())
                        .putopt("hospitalid", drugCodeInfo.getHospitalid())
                        .putopt("doctorname", drugCodeInfo.getDoctorname())
                        .putopt("drugcodes", codes)
                        .putopt("uid", MyApplication.user.getUid()).tostring()).execute(mAbsCallback);
    }


    public void addbuydrugpresent(DrugCodeInfo drugCodeInfo, String codes, String originaldrugcodes, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "addbuydrugpresent")
                .paramsApp("params", new JsonGet().putopt("patienttruename", drugCodeInfo.getTruename()).
                        putopt("patientidcardnum", drugCodeInfo.getIdcardnum())
                        .putopt("patientphonenum", drugCodeInfo.getPhonenum())
                        .putopt("hospitalid", drugCodeInfo.getHospitalid())
                        .putopt("doctorname", drugCodeInfo.getDoctorname())
                        .putopt("originaldrugcodes", originaldrugcodes)
                        .putopt("drugcodes", codes)
                        .putopt("uid", MyApplication.user.getUid()).tostring()).execute(mAbsCallback);
    }


    public void getorderdrugsv2(String orderid, String parentid, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "getorderdrugsv2")
                .paramsApp("params", new JsonGet().putopt("orderid", orderid).
                        putopt("parentid", parentid)
                        .putopt("uid", MyApplication.user.getUid()).tostring()).execute(mAbsCallback);
    }


    /**
     * 输入	公共参数
     * service	string	service = addcoupondrugpresent
     * params	json	json格式的参数串
     * uid	int	用户ID
     * couponcode	String	赠药券码
     * drugcodes	string	药品监管码codes（多个逗号“,”相隔）
     * patienttruename	string	患者姓名
     * patientidcardnum	string	患者身份证号
     * patientphonenum	string	患者手机号
     * hospitalid	int	医院ID（不是必填， 空可以传0）
     * doctorid	int	医生ID（不是必填， 空可以传0）
     * doctorname	string	医生名
     * patientid	Int	病人ID（不是必填， 空可以传0）
     * recipepicsurl	string	处方图片地址，多张以逗号隔开
     *
     * @param couponDrug
     * @param codes
     * @param mAbsCallback
     */
    public void addcoupondrugpresent(CouponDrug couponDrug, String codes, String recipepicsurl,int cardtype, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "addcoupondrugpresent")
                .paramsApp("params",
                        new JsonGet().putopt("couponcode", couponDrug.getCouponcode()).
                                putopt("drugcodes", codes).
                                putopt("patienttruename", couponDrug.getTruename()).
                                putopt("patientidcardnum", couponDrug.getIdcardnum())
                                .putopt("patientphonenum", couponDrug.getPhonenum())
                                .putopt("hospitalid", couponDrug.getHospitalid())
                                .putopt("doctorname", couponDrug.getDoctorname())
                                .putopt("doctorid", 0)
                                .putopt("patientid", 0)
                                .putopt("recipepicsurl", recipepicsurl)
                                .putopt("cardtype",cardtype)
                                .putopt("uid", MyApplication.user.getUid()).tostring()).execute(mAbsCallback);
    }


    /**
     * 11.	药店药品入库-新增入库记录
     *
     * @param from          来货单位
     * @param fromID        来货单位ID
     * @param invoiceMoney  金额
     * @param deliverImgUrl 送货单（拍照）
     * @param drugcodes     批量监管码codes（逗号连接）
     * @param addstocktime  入库时间
     * @param deliverytime  单据时间
     * @param quantity      入库总数量
     * @param mAbsCallback
     */
    public void addstockinlog(String from, int fromID, String invoiceMoney, String deliverImgUrl,
                              String drugcodes, String addstocktime, String deliverytime, int quantity, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "addstockinlog")
                .paramsApp("params", new JsonGet()
                        .putopt("drugcodes", drugcodes)
                        .putopt("addstocktime", addstocktime)
                        .putopt("deliverytime", deliverytime)
                        .putopt("from", from)
                        .putopt("fromid", fromID)
                        .putopt("invoicemoney", invoiceMoney)
                        .putopt("deliverimgurl", deliverImgUrl)
                        .putopt("quantity", quantity)
                        .putopt("uid", MyApplication.user.getUid()).tostring()).execute(mAbsCallback);

    }

    public void getSourcelInfo(String keyword, AbsCallback mAbsCallback) {
        OkHttpUtils.getInstance().post(GenApiHashUrl.apiUrl).tag(this)
                .paramsApp("service", "queryprovider")
                .paramsApp("params", new JsonGet().putopt("uid", MyApplication.user.getUid()).putopt("keyword", keyword).tostring()).execute(mAbsCallback);
    }


    public void getCancel() {
        OkHttpUtils.getInstance().cancelTag(this);
    }
}
